trovefandomcom_es-20200215-history
Módulo:Habilidad
local data = {} -- _format removes class gem icon, toggle details button, shadow around template,and details section. Also reduces sidebar padding, resizes images and text, and adds a border. -- local args local _format local shadow = 'black 0 0.1333em 0.3333em 0' local contentHeaderLinear = { 'display' = 'inline', 'white-space' = 'nowrap', 'padding-right' = '.59235em', } function data.main(frame) _format = frame:getParent().args'format' args = frame.args local name = args'nombre' local weapon = args'arma' local class = args'clase' local cooldown = args'enfriamiento' local energy = args'energia' local info = args'info' local notice = args'notice' local image1, div_bkgd, div_margin, toggle_id, title -- Conditionals if string.lower(args'tipo') 'pasiva' then div_bkgd = '#122a42' else div_bkgd = '#062748' end if data.is(args'detalle1') or data.is(args'video') then div_margin = '1em 0 2em' else div_margin = '1em 0 2.231em' end if data.is(weapon) then toggle_id = data.sanitize(weapon .. '_' .. string.sub(info, 1, 3)) title = 'Ataque Básico' image1 = 'Styles_' .. weapon else toggle_id = data.sanitize(name) title = name if data.is(args'imagen') then image1 = args'imagen' end end -- Lua HTML local div = mw.html.create('div') :css({ 'padding' = "1em 1em 0", 'font-size' = ".9375em", 'box-shadow' = shadow, 'overflow' = 'hidden', 'position' = 'relative', 'margin' = div_margin, 'background' = div_bkgd }) :attr('id','Anchor_' .. data.sanitize(title)) :node(data.notice(notice)) -- Notice :node(data.toggle(toggle_id)) -- Toggle Button :tag('table') -- Start of content :css({ 'border-bottom' = '.0667em solid rgba(255,255,255,0.25)', 'padding' = '.13334em' }) :tag('tr') :tag('td') -- Title :css({ 'white-space' = 'nowrap', 'font-size' = '1.4em', 'color' = '#ffed79', 'font-weight' = 'bold', 'text-shadow' = '0 0.0952em black', 'padding-right' = '.66667em' }) :wikitext(title) :done() :tag('td') -- Top section info :css({ 'width' = '99%', 'font-size' = '.89em', 'font-weight' = 'bold', 'padding-right' = '3.7453em' }) :node(data.cooldown(cooldown)) :node(data.energy(energy)) :node(data.loop(1, 5, 1, 'top')) :done() :done() :done() :tag('table') :node(data.tBody(1, image1, info, class)) -- First row :node(data.tBody(2, args'image2', args'info2')) -- Second row :node(data.tBody(3, args'image3', args'info3')) -- Third row :tag('tr') -- Anchor row :addClass('anchor_for_the_table_cells') :css('font-size', '0') :tag('td') :done() :tag('td') :css('width', '66%') :attr('colspan', '1') :done() :tag('td') :css('width', '33%') :done() :done() :done() :done() -- Details section if (data.is(args'detalle1') or data.is(args'video')) and not data.is(_format, 'tooltip') then local vid = '' if args'video' and args'video' ~= '' then vid = string.format('border|270px', args'video') end local details = mw.html.create('div') :css({ 'position' = 'relative', 'top' = '-1.563em', 'margin' = '0 2.1875em -2.1875em 2.1875em', 'padding-bottom' = '1.5625em' }) :tag('div') :addClass('mw-collapsible mw-collapsed') :attr('id', 'mw-customcollapsible-' .. toggle_id) :css('font-size', '.8125em') :tag('div') :addClass('mw-collapsible-content') :css({ 'overflow' = 'auto', 'border-bottom' = '.0769em solid rgb(64, 64, 64)' }) :tag('div') :css({ 'float' = 'right', 'margin' = '1% 0 0 1%', }) :wikitext(vid) :done() :wikitext('Notas:') :tag('ul') :node(data.loop(1, 10, 1, 'detalle')) :done() :done() :done() :done() return mw.allToString(div, details) end -- Styling Changes for Tooltips if data.is(_format, 'tooltip') then div :css({ 'border-radius' = '7px', 'border' = 'solid 1px', 'font-size' = '.8375em', 'width' = '633px' }) :css('box-shadow', nil) :done() end return tostring( div ) end -- Parser function #if: statement function data.is(word, compare) if word and word ~= '' then -- Parser function #ifeq: statement if compare then if compare word then return true else return false end end return true else return false end end -- Remove illegal characters function data.sanitize(word) word = string.gsub(word, '%c%p%s', '_') return word end -- Notice message function data.notice(notice) local div = mw.html.create('div') :css({ 'text-align' = 'center', 'background-color' = '#ab0000', 'color' = 'white', 'width' = '93%', 'margin' = '0 auto .2em', 'border-radius' = '4px' }) :wikitext(notice) return div end -- Toggle button function data.toggle(toggle_id) if (data.is(args'detalle1') or data.is(args'video')) and not data.is(_format, 'tooltip') then local elem = mw.html.create('div') :attr({ 'title' = 'Toggle Details', 'class' = 'mw-customtoggle-' .. toggle_id }) :css({ 'position' = 'absolute', 'width' = '1.734em', 'height' = '1.734em', 'cursor' = 'pointer', 'right' = '.578em', 'top' = '.4em', 'box-shadow' = shadow, 'background-color' = '#031e3a' }) :tag('span') -- Toggle icon :css({ 'top' = '.34em', 'left' = '.5em', 'position' = 'absolute', 'transform' = 'rotate(45deg)', '-webkit-transform' = 'rotate(45deg)', 'border-width' = '0 .267em .267em 0', 'border' = 'solid white', 'display' = 'inline-block', 'padding' = '.2667em' }) :done() :done() return tostring(elem) else return nil end end -- Cooldown icon function data.cooldown(cooldown) if data.is(cooldown) then -- Resize for tooltip local size = 18 if data.is(_format, 'tooltip') then size = 14 end --------------------- local elem = mw.html.create('div') :css(contentHeaderLinear) :css('cursor', 'help') :attr('title', 'Enfriamiento') :wikitext(string.format('text-bottom|%spx|link=|alt=Enfriamiento %ss', size, cooldown)) :done() return tostring(elem) else return nil end end -- Energy icon function data.energy(energy) if data.is(energy) then -- Resize for tooltip local size = 18 if data.is(_format, 'tooltip') then size = 14 end --------------------- local elem = mw.html.create('div') :css(contentHeaderLinear) :css('cursor', 'help') :attr('title', 'Energía') :wikitext(string.format('text-bottom|x%spx|link=|alt=Coste de Energía %s', size, energy)) :done() return tostring(elem) else return nil end end -- Image caption function data.capt(picture) if data.is(picture) and string.sub(picture, 1, 7) 'Styles_' then -- If pic contains Styles_ local _,n = string.find(picture, '_', 8) if data.is(n) then -- If class gem n = n-1 end return 'Weapon: ' .. string.sub(picture, 8, n) else return picture end end -- Info section width function data.width(picture, tr_num) if data.is(args.. tr_num .. '.1') and data.is(picture) then return '1' elseif data.is(args.. tr_num .. '.1') or data.is(picture) then return '2' else return '3' end end -- Main table body generator function data.tBody(tr_num, picture, information, class) if (tr_num ~= 1 and data.is(args.. tr_num)) or tr_num 1 then local tr = mw.html.create('tr') if data.is(picture) then -- image -- Image dimensions local image_size if data.is(class) then image_size = 64 else image_size = 51 end if data.is(_format, 'tooltip') then image_size = image_size - 10 end -------------------- tr:tag('td') :css({ 'padding' = '.4667em', 'vertical-align' = 'top' }) :tag('div') :css('box-shadow', shadow) :wikitext(string.format(' ', picture, image_size, data.capt(picture))) :done() :done() end if data.is(information) then -- info tr:tag('td') :css({ 'vertical-align' = 'top', 'padding' = '0 0 0 .4667em', 'width' = textWidth, }) :attr('colspan', data.width(picture, tr_num)) :wikitext(information) :done() end if data.is(args.. tr_num .. '.1') then -- sidebar tr:tag('td') :css({ 'vertical-align' = 'top', 'padding' = '.325em .4375em 0 .4375em' }) :node(data.loop(tr_num+0.1, tr_num+0.4, 0.1, 'side')) :done() end if data.is(class) and tr_num 1 and not data.is(_format, 'tooltip') then -- Class gem tr:tag('td') :wikitext(string.format('right|top|Este modificador de habilidad requiere una Gema de Clase de %s para ser equipada|link=Gema de Clase', class, class)) :done() end return tostring(tr) else return nil end end -- Iterator for header, sidebars, and details function data.loop(start, maximum, increment, key) local temp_var = '' local once = false local elem local sidebar_css = { 'background-color' = '#0e1b2c', 'padding' = '0 1.3em', 'text-overflow' = 'ellipsis', 'overflow' = 'hidden', 'white-space' = 'nowrap', 'border-radius' = '.3em', 'font-weight' = 'bold' } -- Reduce padding if tooltip if data.is(_format, 'tooltip') then sidebar_css'padding' = '0 2%' end ---------------------------- for i = start, maximum, increment do if data.is(args.. i) then -- If top header if key 'top' then elem = mw.html.create('div') :css(contentHeaderLinear) :tag('span') :css('color', '#ffed79') :wikitext(string.upper(args.. i) .. ':') :done() :wikitext(' ' .. args.. 'v' .. i) :done() temp_var = temp_var .. tostring(elem) end -- If sidebars if key 'side' then -- Every sidebar but the first in each row much have a margin if once and not data.is(sidebar_css'margin') then sidebar_css'margin' = '.325em 0 .0625em;' end elem = mw.html.create('div') :css(sidebar_css) :tag('span') :css({ 'font-weight' = 'bold', 'color' = '#fdf1a0', 'font-size' = '.89em', 'text-transform' = 'uppercase' }) :wikitext(args.. i .. ':') :done() :wikitext(' ' .. args.. 'v' .. i) :done() temp_var = temp_var .. tostring(elem) once = true end -- If details if key 'detalle' then elem = mw.html.create('li') :wikitext(args.. i) temp_var = temp_var .. tostring(elem) end end end sidebar_css'margin' = nil return temp_var end return data